import java.util.concurrent.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 19182
 * Date: 2025-08-26
 * Time: 19:35
 */
public class demo2 {
    public static void main(String[] args) {
        int corePoolsize = 10; //核心线程数
        int maximumPoolsize = 15; //最大线程数
        int keepAliveTime = 5; //非核心线程空闲后, 存活的时间
        BlockingQueue<Runnable> blockingQueue = new ArrayBlockingQueue<>(10); //一次最多存储10个任务
        ThreadFactory threadFactory = Executors.defaultThreadFactory(); //默认工厂
        RejectedExecutionHandler handler = new ThreadPoolExecutor.AbortPolicy();
        ThreadPoolExecutor pool = new ThreadPoolExecutor(
                corePoolsize,
                maximumPoolsize,
                keepAliveTime,
                TimeUnit.SECONDS,
                blockingQueue,
                threadFactory,
                handler
        );
        for(int i = 0; i < 100; i++){
            pool.submit(()->{
                System.out.println(Thread.currentThread().getName() + "线程执行");
            }, i);
        }
    }
}
